

#ifndef SIMPLEINDEXINGCACHE_H_
#define SIMPLEINDEXINGCACHE_H_

#include "../Packets/PubPkt.h"
#include <boost/unordered_map.hpp>
#include <set>
#include "../Common/Consts.h"
#include <iostream>
#include <map>
#include "../Common/Timer.h"


class SimpleIndexingCache {

public:

	SimpleIndexingCache();

	virtual ~SimpleIndexingCache();

	bool insert(PubPkt *pkt, key_t k);

	bool remove(std::pair<timestamp_t, key_t> key);

	void extract(int type, Constraint* parCostraint, int parNumConstraint, timestamp_t parEntryTimestamp, float window, OccurrenceType occurrence, std::set<PubPkt*> &resultSet);

private:

	typedef struct {
		ValType valType;
		boost::unordered_map<std::string, std::set<std::pair<timestamp_t, key_t> > > *stringIndex;
		boost::unordered_map<bool, std::set<std::pair<timestamp_t, key_t> > > *boolIndex;
		std::map<int, std::set<std::pair<timestamp_t, key_t> > > *intIndex;
		std::map<float, std::set<std::pair<timestamp_t, key_t> > > *floatIndex;
	} SimpleIndexType;

	boost::unordered_map<int, boost::unordered_map<std::string, SimpleIndexType*> > indexMap;
	boost::unordered_map<key_t, PubPkt*> cacheTable;

	Timer *timer;
};


#endif /* SIMPLEINDEXINGCACHE_H_ */
